//
//  UIImage+AlphaImage.m
//  suishouxiu
//
//  Created by parkin on 15/5/21.
//  Copyright (c) 2015年 zhongyan. All rights reserved.
//

#import "UIImage+AlphaImage.h"
#import "UIView+Frame.h"
#import "UIColor+HEX.h"
//#import "SSXText.h"
#import "Config.h"
@implementation UIImage(AlphaImage)
+ (UIImage *)imageWithView:(UIView *)view {
    CGFloat scale = 3;
    UIGraphicsBeginImageContext(CGSizeMake(view.width * scale , view.height * scale));
//    UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.width * scale , view.height * scale), view.opaque, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, view.backgroundColor.CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, view.width * scale , view.height * scale ));
    
//    CGFloat red = 0, green = 0, blue = 0, alpha = 1;
//    [text.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
//    CGContextSetCharacterSpacing (context, 10);
//    CGContextSetTextDrawingMode (context, kCGTextFill);
//    CGContextSetRGBFillColor (context, red, green, blue, alpha);
  
    
    CGContextScaleCTM(context, scale, scale);
    [view.layer renderInContext:context];
    
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;

}
+ (UIImage *)imageWithTextView:(UITextView *)text {
    CGFloat scale = 1;

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(text.width * scale , text.height * scale), 0, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, text.backgroundColor.CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, text.width * scale  , text.height * scale));
    CGContextScaleCTM(context, scale, scale);
    [text.textInputView.layer renderInContext:context];
    
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
@end
